/**
 * create by young (young2f@outlook.com) on 2020/12/4
 */
'use strict';
const model = require('../base/modelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    name: {
      type: String, _type: 'string', title: '商品/物料名称', enableArea: [
        'table'
      ]
    },
    count: {
      type: Number, _type: 'number', title: '数量', enableArea: [
        'table'
      ]
    },
    orderCode: {
      type: String, _type: 'string', title: '订单/采购单号', enableArea: [
        'table'
      ]
    },
    createdType: {//订单创建或非订单创建
      type: String, _type: 'string', title: '创建类型', enableArea: [
        'table'
      ], default: '出货单'
    },
    deliverChannel: {
      type: String, _type: 'string', title: '承运人名称', required: true, enableArea: [
        'table'
      ]
    },

    shippingFee: {
      type: Number, _type: 'number', title: '运费',  enableArea: [
        'table'
      ]
    },
    paymentAmount: {
      type: Number, _type: 'number', title: '运费付款', enableArea: [
        'table'
      ], default: 0
    },
    lotCode: {
      type: String, _type: 'string', title: '批次号', enableArea: [
        'table'
      ]
    },
    pmLotId: {
      type: String, _type: 'string', title: '采购物料批次编号', enableArea: [
        'table'
      ]
    },
    memo: {
      type: String, _type: 'string', title: '备注', enableArea: [
        'table'
      ]
    },
  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  return connect.model('ShippingFee', _schema);
};
